package com.data.model.sqlclause.where.basic;

import com.data.model.constant.SqlConstant;
import com.data.model.sqlclause.where.basic.AtomicCondition;
import lombok.Data;

import java.util.List;
import java.util.stream.Collectors;

@Data
public abstract class MultipleValueAtomicCondition extends AtomicCondition {
    private List<Object> listValue;

    private String getValueString(Object value) {
        if (value instanceof List<?>) {
            List<?> list = (List<?>) value;
            return list.stream().map(this::getValueString).collect(Collectors.joining(",", "(", ")"));
        }
        if (value instanceof String) {
            return "'" + value.toString() + "'";
        }
        return value.toString();
    }

    @Override
    public String toConditionStr() {
        return getKey() + SqlConstant.SPACE + getOperator() + SqlConstant.SPACE + getValueString(this.listValue);
    }

    @Override
    public boolean valid() {
        return true;
    }
}
